/**
 * 
 */
package gdr.player;

import gdr.action.*;

/**
 * Personaggio di base
 * @author Giorgio Vitale
 */
public class DefaultPlayer
{	//parametri per il calcolo dell'esperienza necessaria a raggiungere il livello successivo
	protected static final double A = 0.0085;
	protected static final double B = 0.15;
	protected static final double C = 1.05;
	protected static final double D = 1.01;
	protected static final double E = 20;
	protected static final double F = 350;

	/** Nome del personaggio*/
	protected String name;
	/** Livello del personaggio */
	protected int level;
	/** Punti esperienza necessari a raggiungere il livello successivo*/
	protected int expNextLevel;
	/** Classe del personaggio */
	protected Classe classe;
	/** Statistiche di base */
	protected Statistiche baseStat;
	/** incremento delle statistiche*/
	protected Statistiche incrementStat;
	/** Statistiche attuali*/
	protected Statistiche actualStat;
	/** team del personaggio*/
	protected Team team;
	
	public DefaultPlayer()
	{	baseStat = new Statistiche();
		incrementStat = new Statistiche();
	}
	
	public int getMaxStat(int stat){
		float inc = ((float)incrementStat.getStat(stat))/100;
		return (int)(baseStat.getStat(stat)*(1+inc*level));
	}
	
	/**
	 * Dato un livello, calcola l'esperienza necessaria a raggiungere il successivo
	 * @param level
	 * @return
	 */
	public int expToNextLevel(int level)
	{	if (level<=99) 
		{	return (int) (Math.pow(level, 4)*A + Math.pow(level, 3)*B + Math.pow(level, 2)*C + level * D + E);
		}
		else
		{	return (int) (expToNextLevel(99) + (level-99)*F);
		}
	}
	
	/**
	 * Aumenta l'esperienza del personaggio
	 * @param exp
	 * @return true se aumentando l'esperienza si effettua un levelup
	 */
	public boolean gainExperience(int exp)
	{	if (exp<0) return false;
		boolean levelup = exp>=getExpNextLevel();
		while (exp!=0)
		{	if (exp<getExpNextLevel())
			{	setExpNextLevel(getExpNextLevel()-exp);
				exp = 0;
			}
			else
			{	exp -= getExpNextLevel();
				level++;
				setExpNextLevel(expToNextLevel(level));
			}
		}
		return levelup;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Statistiche getBaseStat() {
		return baseStat;
	}
	public void setBaseStat(Statistiche baseStat) {
		this.baseStat = baseStat;
	}
	public Statistiche getIncrementStat() {
		return incrementStat;
	}
	public void setIncrementStat(Statistiche incrementStat) {
		this.incrementStat = incrementStat;
	}
	public Statistiche getActualStat() {
		return actualStat;
	}
	public void setActualStat(Statistiche actualStat) {
		this.actualStat = actualStat;
	}
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public int getExpNextLevel() {
		return expNextLevel;
	}
	public void setExpNextLevel(int expNextLevel) {
		this.expNextLevel = expNextLevel;
	}
	public Classe getClasse() {
		return classe;
	}
	public void setClasse(Classe classe) {
		this.classe = classe;
	}
	public Team getTeam() {
		return team;
	}
	public void setTeam(Team team) {
		this.team = team;
	}

	@Override
	public String toString() {
		return "DefaultPlayer [name=" + name + ", level=" + level
				+ ", expNextLevel=" + expNextLevel + ", playerClass="
				+ classe + ", baseStat=" + baseStat + ", incrementStat="
				+ incrementStat + ", actualStat=" + actualStat + ", team="
				+ team + "]";
	}
}